package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

type ArticleOrder struct {
	ent.Schema
}

func (ArticleOrder) Fields() []ent.Field {
	return []ent.Field{
		field.Int("id"),
		field.Int("user_id").Optional().Default(0),
		field.Int("article_id").Optional().Default(0),
		field.Int("price").Default(0),
		field.Time("create_time").Default(time.Now),
		field.Time("update_time").Default(time.Now).UpdateDefault(time.Now),
	}
}

func (ArticleOrder) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("User", User.Type).
			Ref("articleOrders").Field("user_id").
			Unique(),
		edge.From("articleBase", Article.Type).
			Ref("orders").Field("article_id").
			Unique(),
	}
}
